package com.java.task20.work2;

import java.io.*;

public class PrintStreamTest {
    public static void main(String[] args) {
        BufferedReader br = null;
        PrintStream ps = null;
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            ps = new PrintStream(new FileOutputStream("d:abc.txt"));
            boolean boo = true;
            while (true) {
                //提示用户输入信息
                System.out.println("请" +(boo?"第一个同学":"第二个同学")+"输入内容：");
                //将输入的信息储存在str中111
                String str = br.readLine();
                //判断输入的内容是否为end如果为end则聊天结束
                if ("end".equals(str)) {
                    System.out.println("聊天结束！");
                    break;
                }
                //打印输入的内容
                    ps.println((boo?"第一个同学说:":"第二个同学说:")+str);
                boo = !boo;
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            //关闭流
            if (ps != null) {
                ps.close();

            }
            if (ps != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
